/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2009 - 2012 Luca Mingardi.
 *
 * This file is part of jeeObserver.
 *
 * JeeObserver is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * JeeObserver is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */
package jeeobserver.server.settings;

import java.io.Serializable;
import jeeobserver.Observer;
import jeeobserver.server.settings.Condition.TextCondition;

/**
 * The Class Rule.
 *
 * @author Luca Mingardi
 * @version 4.0
 */
public abstract class Rule implements Serializable {

	 /** The Constant serialVersionUID. */
	 private static final long serialVersionUID = 40L;

	 /** The active. */
	 private boolean active = true;

	 /** The context name condition. */
	 private TextCondition contextCondition;

	 /**
	  * Checks if is core element in rule.
	  *
	  * @param observer the observer
	  *
	  * @return true, if is core element in rule
	  */
	 public boolean isObserverInRule(Observer observer) {
			if (this.isActive()) {
				 if ((this.contextCondition == null) || this.contextCondition.checkValue(observer.getContext())) {
						return true;
				 }
			}
			return false;
	 }
	 /** The name. */
	 private String name;

	 /**
	  * Gets the name.
	  *
	  * @return the name
	  */
	 public String getName() {
			return this.name;
	 }

	 /**
	  * Sets the name.
	  *
	  * @param name the new name
	  */
	 public void setName(String name) {
			this.name = name;
	 }

	 /**
	  * Checks if is active.
	  *
	  * @return true, if is active
	  */
	 public boolean isActive() {
			return this.active;
	 }

	 /**
	  * Sets the active.
	  *
	  * @param active the new active
	  */
	 public void setActive(boolean active) {
			this.active = active;
	 }

	 /**
	  * Gets the context name condition.
	  *
	  * @return the context name condition
	  */
	 public TextCondition getContextCondition() {
			return this.contextCondition;
	 }

	 /**
	  * Sets the context name condition.
	  *
	  * @param contextCondition the new context name condition
	  */
	 public void setContextCondition(TextCondition contextCondition) {
			this.contextCondition = contextCondition;
	 }
}
